package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.dto.system.SysRoleDto;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/system/sysRole/")
@CrossOrigin(allowCredentials = "true" , originPatterns = "*" , allowedHeaders = "*")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;


    @GetMapping("/getSysRoleListByPage/{page}/{limit}")
    public Result<PageInfo<SysRole>> getSysRoleListByPage(@PathVariable Integer page, @PathVariable Integer limit,
                                       @ModelAttribute  SysRoleDto sysRoleDto){
        PageInfo<SysRole> pageInfo=sysRoleService.getSysRoleListByPage(page,limit,sysRoleDto);
        return Result.ok(pageInfo);
    }

    @PutMapping("/updateSysRole")
    public Result updateSysRole(@RequestBody SysRole sysRole){
        sysRoleService.updateSysRole(sysRole);
        return Result.ok(null);
    }

    @PostMapping("/saveSysRole")
    public Result saveSysRole(@RequestBody SysRole sysRole){
        sysRoleService.saveSysRole(sysRole);
        return Result.ok(null);
    }
    @DeleteMapping("/deleteById/{roleId}")
    public Result deleteById(@PathVariable Long roleId){
        sysRoleService.deleteById(roleId);
        return Result.ok(null);
    }
    @GetMapping("/findAllRoles/{userId}")
    public Result<Map<String,Object>> findAllRoles(@PathVariable("userId") Long userId){
        Map<String,Object> map = sysRoleService.findAllRoles(userId);
        return Result.ok(map);
    }
}
